package com.nikkerball.apps.darkhorse.dao.hibernate;

import com.nikkerball.apps.darkhorse.dao.SecurityDao;
import com.nikkerball.apps.darkhorse.model.security.User;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import java.util.List;

/**
 * TODO: Document class
 *
 * @author marius (created on 2010-12-14)
 */
public class SecurityDaoHibernateImpl extends HibernateDaoSupport implements SecurityDao {
    @SuppressWarnings({"unchecked"})
    public User getUserByUserNameOrEmailAddress(String userName, String emailAddress) {
        List<User> users = getHibernateTemplate()
                .find("from User user where user.userName = ? or user.emailAddress = ?",
                        new Object[]{userName, emailAddress});
        if (users.isEmpty()) {
            return null;
        } else {
            return users.get(0);
        }
    }
}
